﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
<link href="~/lib/layui/css/layui.css" rel="stylesheet" />
<script src="~/lib/layui/layui.js"></script>
<script src="~/lib/jquery/dist/jquery.js"></script>

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>IMES</title>
</head>
<body>
    <div class="layui-panel">
        <div style="padding: 32px;">
            <div class="layui-form-item">
                <form class="layui-form" action="">
                    <div class="layui-form-item">
                        <label class="layui-form-label">单据编号:</label>
                        <div class="layui-input-block">
                            <input type="text" Id="orderNo" placeholder="请输入，忽略将自动生成" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">备注:</label>
                        <div class="layui-input-block">
                            <textarea Id="orderNotes" type="text" placeholder="请输入备注" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </form>
            </div>
        </div>
        <div class="layui-panel" style="margin-top: 20px;">
            <div style="padding: 32px;">
                <div class="layui-form-item">
                    <div class="layui-form-label">产品明细</div>
                    <div style="margin-left:800px" class="layui-inline">
                        <a class=" layui-btn-sm" lay-on="test-page-custom">+选择产品</a>
                        <a class=" layui-btn-sm">删除行</a>
                        <a class=" layui-btn-sm">刷新</a>
                    </div>
                </div>

                <table class="layui-table">
                    <thead>
                        <tr>
                            <th>
                                <input type="checkbox" name="check"></input>
                            </th>
                            <th>产品编号</th>
                            <th>产品名称</th>
                            <th>产品规格</th>
                            <th>工单编号</th>
                            <th>数量</th>
                            <th>完成数</th>
                            <th>创建时间</th>
                            <th>创建人</th>
                            <th>修改人</th>
                            <th>修改时间</th>
                        </tr>
                    </thead>
                    <tbody id="body">
                    </tbody>
                </table>
                <div>
                    @* 红色保存按钮 *@
                    <button class="layui-btn layui-btn-danger" lay-submit lay-filter="add">修改</button>
                    <button type="reset" class="layui-btn layui-btn-primary">关闭</button>
                </div>
            </div>
        </div>
    </div>
    <!-- 请勿在项目正式环境中引用该 layui.js 地址 -->
    <script src="//unpkg.com/layui@2.9.20/dist/layui.js"></script>
    <script>
        function getOrder() {
            var orderId = location.href.split("=")[1];
            //反填
            $.ajax({
                url: '@ViewBag.Darius' + "/api/Orders/GetOrderPro",
                type: "post",
                async: false,
                data: JSON.stringify({orderId: orderId}),
                dataType: "json",
                contentType: "application/json",
                success: function (res) {
                    console.log(res)
                    var data = res.data1;
                        $("#orderNo").val(data.orderNo);
                        $("#orderNotes").val(data.orderNotes);
                        var tbody = $("#body");
                        tbody.empty();
                       console.log(data.orderDetail);
                    // $.each(data.orderDetails, function (i, item) {
                    //     var td1 = $("<td>${item.productNo}</td>");
                    //     var td2 = $("<td></td>");
                    //     var td3 = $("<td></td>");
                    //     var td4 = $("<td></td>");
                    //     var td5 = $("<td></td>");
                    //     var td6 = $("<td></td>")
                    //     var td7 = $("<td></td>");
                    //     var td8 = $("<td></td>");
                    //     var td9 = $("<td></td>");
                    //     var td10 = $("<td></td>");
                    // });
                       //循环填充数据
                       for (var i = 0; i < data.orderDetail.length; i++) {
                           var tr = $("<tr></tr>");
                           var td1 = $("<td><input type='checkbox' name='check'></input></td>");
                           var td2 = $("<td>" + data.orderDetail[i].productNumber + "</td>");
                           var td3 = $("<td>" + data.orderDetail[i].productName + "</td>");
                           var td4 = $("<td>" + data.orderDetail[i].productSpec + "</td>");
                        var td5 = $("<td>" + data.orderDetail[i].workOrder + "</td>");
                        var td6 = $("<td>" + data.orderDetail[i].productNum + "</td>");
                        var td7 = $("<td>" + data.orderDetail[i].completedQuantity + "</td>");
                           var td8 = $("<td>" + data.orderDetail[i].createTime + "</td>");
                           var td9 = $("<td>" + data.orderDetail[i].createUser + "</td>");
                           var td10 = $("<td>" + data.orderDetail[i].modifyUser + "</td>");
                           var td11 = $("<td>" + data.orderDetail[i].modifyTime + "</td>");
                           tr.append(td1, td2, td3, td4, td5, td6, td7, td8, td9, td10, td11);
                           tbody.append(tr);
                       }
                
                }
            });
        }
        $(function () {
            getOrder();
        });

    </script>
    </body>

</html>
